﻿<phone:PhoneApplicationPage x:Class="AuchanScan.Views.ScanProductPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" mc:Ignorable="d"
                            d:DesignWidth="656" d:DesignHeight="480" FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="PortraitOrLandscape" Orientation="Landscape" shell:SystemTray.IsVisible="True"
                            shell:SystemTray.Opacity="0" shell:SystemTray.ForegroundColor="Black"
                            DataContext="{Binding Path=MainViewModel,Source={StaticResource ViewModelLocator}}"
                            OrientationChanged="PhoneApplicationPage_OrientationChanged"
							toolkit:TiltEffect.IsTiltEnabled="True"
							xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
							xmlns:behaviors="clr-namespace:AuchanScan.Interactions">
    <phone:PhoneApplicationPage.Resources>

        <Style x:Key="TRProgressBarStyle" TargetType="ProgressBar">
            <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}" />
            <Setter Property="Background" Value="{StaticResource PhoneAccentBrush}" />
            <Setter Property="Maximum" Value="100" />
            <Setter Property="IsHitTestVisible" Value="False" />
            <Setter Property="Padding" Value="{StaticResource PhoneHorizontalMargin}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ProgressBar">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Determinate" />
                                    <VisualState x:Name="Indeterminate">
                                        <Storyboard Duration="00:00:04.4" RepeatBehavior="Forever">
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                     Storyboard.TargetName="DeterminateRoot">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name="DeterminateRoot" Visibility="Visible" Margin="12,40,12,0">
                                <Rectangle x:Name="ProgressBarTrack" Fill="{TemplateBinding Background}" Height="10" Opacity="0.1" />
                                <Rectangle x:Name="ProgressBarIndicator" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Left"
                           Height="10" />
                            </Grid>
                            <TextBlock TextWrapping="Wrap" Text="1 TR" VerticalAlignment="Center" HorizontalAlignment="Center"
                         Foreground="{StaticResource PhoneForegroundBrush}" FontFamily="Segoe WP Semibold" Margin="0,-8,0,0" />
                            <Rectangle Fill="{StaticResource PhoneForegroundBrush}" HorizontalAlignment="Center" Width="2"
                         VerticalAlignment="Center" Height="27" Margin="0,43,0,0" />
                            <TextBlock TextWrapping="Wrap" Text="2 TR" VerticalAlignment="Center" HorizontalAlignment="Right"
                         Foreground="{StaticResource PhoneForegroundBrush}" FontFamily="Segoe WP Semibold" Margin="0,-8,0,0" />
                            <Rectangle Fill="{StaticResource PhoneForegroundBrush}" HorizontalAlignment="Right" Width="2"
                         VerticalAlignment="Center" Height="27" Margin="0,43,12,0" />
                            <TextBlock TextWrapping="Wrap" Text="0 TR" VerticalAlignment="Center" HorizontalAlignment="Left"
                         Foreground="{StaticResource PhoneForegroundBrush}" FontFamily="Segoe WP Semibold" Margin="0,-8,0,0" />
                            <Rectangle Fill="{StaticResource PhoneForegroundBrush}" HorizontalAlignment="Left" Width="2"
                         VerticalAlignment="Center" Height="27" Margin="11,43,0,0" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Storyboard x:Name="StoryboardShowChangeQuantity">
            <DoubleAnimation Duration="0:0:0.4" To="0"
                       Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="grid"
                       d:IsOptimized="True">
                <DoubleAnimation.EasingFunction>
                    <CircleEase EasingMode="EaseOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>
        <Storyboard x:Name="StoryboardHideChangeQuantity">
            <DoubleAnimation Duration="0:0:0.4" To="-135"
                       Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="grid"
                       d:IsOptimized="True">
                <DoubleAnimation.EasingFunction>
                    <CircleEase EasingMode="EaseOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>
    </phone:PhoneApplicationPage.Resources>
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar>
            <shell:ApplicationBarIconButton IconUri="/icons/appbar.add.rest.png" IsEnabled="True" Text="ajouter"
                                      Click="Add_Click" />
            <shell:ApplicationBarIconButton IconUri="/icons/appbar.minus.rest.png" IsEnabled="True" Text="supprimer"
                                      Click="Remove_Click" />
            <shell:ApplicationBarIconButton IconUri="/icons/appbar.creditcard.png" IsEnabled="True" Text="en caisse"
                                      Click="Buy_Click" />
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="vider le panier" Click="EmptyCart_Click" />
                <shell:ApplicationBarMenuItem Text="trophées pouvant être acquis" Click="Trophyize_Click" />
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">
        <!--TitlePanel contains the name of the application and page title-->
        <!--ContentPanel - place additional content here-->
        <Image Source="../images/Page_Background2.png" Stretch="Fill" />

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Margin="12,35,12,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <ListBox x:Name="ListAchat" ItemsSource="{Binding Datas.Courses}"
               SelectedItem="{Binding CurrentProduct, Mode=TwoWay}"
               ItemContainerStyle="{StaticResource StretchListBoxItemStyle}"
               Grid.Row="2" Grid.ColumnSpan="3" Margin="0,12,0,0">
                <i:Interaction.Behaviors>
                    <behaviors:ContinuumMasterBehavior />
                </i:Interaction.Behaviors>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Button Style="{StaticResource ButtonNoStyle}" Click="Nav_Product">
                            <Grid Margin="0,0,0,6">
                                <toolkit:ContextMenuService.ContextMenu>
                                    <toolkit:ContextMenu Background="White" IsZoomEnabled="False">
                                        <toolkit:MenuItem Foreground="Black" Header="changer la quantité" Click="ChangeQuantity_Click" />
                                        <toolkit:MenuItem Foreground="Black" Header="mettre de côté" Click="ToBuyList_Click" />
                                    </toolkit:ContextMenu>
                                </toolkit:ContextMenuService.ContextMenu>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                    <RowDefinition Height="auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding Quantity}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center"  />
                                <TextBlock Text="{Binding Product.Name}" Grid.Column="1" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center" TextWrapping="Wrap"
          behaviors:ContinuumAnimation.IsContinuumItem="True"/>
                                <TextBlock Text="{Binding TotalPrice}" Grid.Column="2" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Top" Margin="12,0,0,0"  />
                                <TextBlock Text="€" Grid.Column="3" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Top"  />
                                <Grid Visibility="{Binding HasPromo,Converter={StaticResource VisibilityConverter}}" Grid.ColumnSpan="4" Grid.Row="1" Margin="0,0,12,0"
             >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="60"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Path Visibility="{Binding UsePromo, Converter={StaticResource VisibilityConverter}}" Data="M0,119 L31,92 L119,185 L267,0 L300,24 L122,250 z" Fill="{StaticResource PhoneRadioCheckBoxCheckBrush}" HorizontalAlignment="Center" Height="18" IsHitTestVisible="False" Stretch="Fill" StrokeThickness="2" StrokeLineJoin="Round" VerticalAlignment="Center" Width="24" UseLayoutRounding="False" Grid.Column="3"/>
                                    <Border 	Visibility="{Binding HasPromo, Converter={StaticResource VisibilityConverter}}" 
		 		Background="{StaticResource AccentBrushScan}" Grid.Column="1" Width="4" HorizontalAlignment="Left" />
                                    <TextBlock Text="{Binding Promotion.Comment1}" Style="{StaticResource PhoneTextSubtleStyle}" VerticalAlignment="Center" Grid.Column="2" FontSize="21.333" />
                                </Grid>
                            </Grid>
                        </Button>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <TextBlock TextWrapping="Wrap" Text="TOTAL :" Style="{StaticResource PhoneTextLargeStyle}" FontWeight="Bold" HorizontalAlignment="Right" />
            <TextBlock TextWrapping="Wrap" Text="{Binding TotalPrice, Mode=OneWay}" Style="{StaticResource PhoneTextGroupHeaderStyle}" FontWeight="Bold" HorizontalAlignment="Right" Grid.Column="1" Margin="0" />
            <TextBlock TextWrapping="Wrap" Text="€" Style="{StaticResource PhoneTextGroupHeaderStyle}" FontWeight="Bold" HorizontalAlignment="Right" Grid.Column="2" />
            <TextBlock TextWrapping="Wrap" Text="TICKET(S) RESTO :" Style="{StaticResource PhoneTextLargeStyle}" FontSize="26.667" FontWeight="Bold" d:LayoutOverrides="Width" Grid.Row="1" HorizontalAlignment="Right" Margin="12,-6,12,0" />
            <TextBlock TextWrapping="Wrap" Text="{Binding TicketResto, Mode=OneWay}" Style="{StaticResource PhoneTextGroupHeaderStyle}" FontWeight="Bold" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1" Margin="0,-6,0,0" FontSize="26.667" />
            <TextBlock TextWrapping="Wrap" Text="€" Style="{StaticResource PhoneTextGroupHeaderStyle}" FontWeight="Bold" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="2" Margin="12,-6,12,0" FontSize="26.667" />
            <Grid Visibility="{Binding HasProduct, Converter={StaticResource VisibilityConverter}}"  Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image HorizontalAlignment="Center" Source="/icons/appbar.barcode.png" VerticalAlignment="Center" Width="128"/>
                <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Center" Grid.RowSpan="3" Foreground="Black" Style="{StaticResource PhoneTextLargeStyle}" FontSize="29.333" TextAlignment="Center" Text="Pour commencer, appuyez sur &quot;+&quot; pour scannez un article" Grid.Row="1"/>
            </Grid>
        </Grid>
        <Grid x:Name="ChangeQuantity" Visibility="Collapsed" Background="#7FFFFFFF">
            <Grid x:Name="grid" VerticalAlignment="Top" Background="{StaticResource PhoneAccentBrush}"
            RenderTransformOrigin="0.5,0.5">
                <Grid.RenderTransform>
                    <CompositeTransform TranslateY="-134" />
                </Grid.RenderTransform>
                <StackPanel Orientation="Horizontal" Margin="0,6" Height="72">
                    <Button Content="supprimer" Foreground="#DEFFFFFF" BorderBrush="#DEFFFFFF" Click="RemoveItem_Click" />
                    <Button x:Name="DownQuantityButton" Content="-" Width="72" Margin="53,0,12,0" Foreground="#DEFFFFFF"
                  BorderBrush="#DEFFFFFF" FontFamily="Segoe WP Black" Click="DownQuantity_Click" />
                    <TextBlock x:Name="NbrElemn" VerticalAlignment="Center" FontSize="26.667" Foreground="#DEFFFFFF" />
                    <Button Content="+" Width="72" Margin="12,0,0,0" Foreground="#DEFFFFFF" BorderBrush="#DEFFFFFF"
                  FontFamily="Segoe WP Black" Click="UpQuantity_Click" />
                </StackPanel>
            </Grid>
        </Grid>
        <Grid x:Name="LandscapeView" Background="{StaticResource PhoneBackgroundBrush}" Visibility="Collapsed">
            <ProgressBar x:Name="TRProgressBar" Maximum="100" Margin="44,34,44,0" Style="{StaticResource TRProgressBarStyle}" />
            <StackPanel HorizontalAlignment="Left" Margin="12,82,0,0" Orientation="Horizontal" VerticalAlignment="Top">
                <TextBlock TextWrapping="Wrap" Text="TOTAL: " d:LayoutOverrides="Width" FontFamily="Segoe WP Black"
                   FontSize="45.333" />
                <TextBlock TextWrapping="Wrap" Text="{Binding TotalPrice}" d:LayoutOverrides="Width" FontFamily="Segoe WP Black"
                   FontSize="45.333" />
                <TextBlock TextWrapping="Wrap" FontFamily="Segoe WP Black" FontSize="45.333" Text="€" />
            </StackPanel>
            <StackPanel HorizontalAlignment="Left" Margin="16,130,0,0" Orientation="Horizontal" VerticalAlignment="Top"
                  Opacity="0.9">
                <TextBlock TextWrapping="Wrap" Text="NBR: " d:LayoutOverrides="Width" FontFamily="Segoe WP Black" FontSize="24" />
                <TextBlock TextWrapping="Wrap" x:Name="NbrElemInBasket" d:LayoutOverrides="Width" FontFamily="Segoe WP Black"
                   FontSize="24" />
            </StackPanel>
            <StackPanel HorizontalAlignment="Right" Margin="12,82,12,0" Orientation="Horizontal" VerticalAlignment="Top">
                <TextBlock TextWrapping="Wrap" Text="CAGNOTTE:" d:LayoutOverrides="Width" FontFamily="Segoe WP Black"
                   FontSize="45.333" />
                <TextBlock TextWrapping="Wrap" x:Name="Cagnotte" d:LayoutOverrides="Width" FontFamily="Segoe WP Black"
                   FontSize="45.333" />
                <TextBlock TextWrapping="Wrap" FontFamily="Segoe WP Black" FontSize="45.333" Text="€" />
            </StackPanel>
        </Grid>
        <Image Height="64" Source="/images/herbe.png" Stretch="Fill" VerticalAlignment="Bottom" Margin="0,0,0,8" />
        <Rectangle Fill="#FFAB596E" Height="8" VerticalAlignment="Bottom" />
    </Grid>
</phone:PhoneApplicationPage>
